package com.huiminpay.merchant.convert;

import com.huiminpay.merchant.dto.MerchantDTO;
import com.huiminpay.merchant.entity.Merchant;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.ArrayList;
import java.util.List;

@Mapper   //mapstruct注解
public interface MerchantConvert {

    MerchantConvert INSTANCE = Mappers.getMapper(MerchantConvert.class);


    //将实体类转为DTO
    MerchantDTO entity2DTO(Merchant entity);

    //将DTO转为实体类
    Merchant dto2Entity(MerchantDTO dto);

    List<Merchant> dtoListToEntityList(List<MerchantDTO> dtoList);

    List<MerchantDTO> entityListToDTOList(List<Merchant> entityList);

    public static void main(String[] args) {
        //将实体类转换为DTO
        Merchant merchant = new Merchant();
        merchant.setMerchantName("拼多多");
        merchant.setMerchantAddress("北京");
        MerchantDTO merchantDTO = INSTANCE.entity2DTO(merchant);
        merchantDTO.setMobile("18181818181");
//        System.out.println(merchantDTO);

        //将DTO转为实体类
        Merchant merchant1 = INSTANCE.dto2Entity(merchantDTO);
//        System.out.println(merchant1);



        //dtoListToEntityList
        MerchantDTO dto = new MerchantDTO();
        dto.setMerchantName("京东");
        dto.setMerchantAddress("北京");
        dto.setMerchantNo("001");
        ArrayList<MerchantDTO> dtoList = new ArrayList<>();
        dtoList.add(merchantDTO);
        dtoList.add(dto);
        System.out.println(dtoList);
        List<Merchant> merchantsList = INSTANCE.dtoListToEntityList(dtoList);
        System.out.println(merchantsList);

    }

}
